package com.example.chatai.Controller;

import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.ollama.api.OllamaOptions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.HashMap;
import java.util.Map;

import static org.springframework.ai.chat.memory.ChatMemory.CONVERSATION_ID;

@RequiredArgsConstructor
@RestController
@RequestMapping("/ai")
public class ChatController {
/**
 * 作者csdn:胖虎爱java shibaizhelianmeng@163.com
 **/
private  final ChatClient client;
@GetMapping(value = "/chat",produces = "text/html;charset=utf-8")
public Flux<String> chat(String prompt, int chatid, @RequestParam(defaultValue = "deepseek-r1:7b") String model) {
        return client.prompt()
                .options(org.springframework.ai.ollama.api.OllamaOptions.builder()
                        .model(model)
                        .build())
                .user(prompt)
                .advisors(a -> a.param(CONVERSATION_ID, chatid))
                .stream()
                .content();
    }
}
